/*************************************************************************
*																		 *
*				code by Miles Chen (v-mich) 2007.9.27					 *
*																		 *
*																		 *
*************************************************************************/

#pragma once

#include "commdef-int.h"

namespace System{namespace Windows{namespace Forms{
	namespace Controls{

	void SetControlProc(HWND hControl, LONG lpNewProc)
	{
		LONG lpDefaultProc;
		lpDefaultProc = SetWindowLongW(hControl, GWLP_WNDPROC, lpNewProc);
		SetWindowLongW(hControl, GWLP_USERDATA, lpDefaultProc);
	}

	void SetControlProc(HWND hDlg, int nIDDlgItem, LONG lpNewProc)
	{
		SetControlProc(GetDlgItem(hDlg, nIDDlgItem), lpNewProc);
	}

	LRESULT CALLBACK DefEditDoubleProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		if(message == WM_CHAR && wParam != '.' && (wParam < '0' || wParam > '9') && wParam != VK_BACK )
		{
			MessageBeep(MB_OK);
			return 0;
		}
		else 
		{
			return CallWindowProcW((WNDPROC)GetWindowLongW(hWnd, GWLP_USERDATA), hWnd, message, wParam, lParam);
		}
	}

	BOOL SetDoubleValue(HWND hDlg, int nIDDlgItem, double value)
	{
		WCHAR szText[MAX_CHAR];
		WCHAR szBuffer[SHORT_CHAR];

		Convert::DoubleToString(szBuffer, value, 3);
		String::CopyTo(szText, szBuffer);

		return SetDlgItemTextW(hDlg, nIDDlgItem, szText);
	}

}}}}